﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XYTXL.API;
using XYTXL.Data;
using XYTXL.AppCode;

namespace XYTXL.Web.View.UCMangForm
{
    public partial class LMGL : FormUControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                
            }
        }

        /// <summary>
        /// 新增时验证栏目重复
        /// </summary>
        /// <param name="strActionType"></param>
        /// <returns></returns>
        public override string VerifyAddForm(string strActionType)
        {
            int TopId = Convert.ToInt32(ddlTopID.SelectedValue);
            JH_MH_LMGL Model = new JH_MH_LMGLB().GetEntity(p => p.TopID == TopId && p.Name == txtName.Text && p.IsDel == 0);

            string strMsg = string.Empty;
            if (Model != null)
            {
                strMsg = "此栏目已经存在！";
            }
            return strMsg;
        }
        /// <summary>
        /// 修改时验证栏目重复
        /// </summary>
        /// <param name="intFormID"></param>
        /// <param name="strActionType"></param>
        /// <returns></returns>
        public override string VerifyUpdateForm(int intFormID)
        {
            int TopId = Convert.ToInt32(ddlTopID.SelectedValue);
            JH_MH_LMGL Model = new JH_MH_LMGLB().GetEntity(p => p.TopID == TopId && p.Name == txtName.Text && p.IsDel == 0 && p.ID != intFormID);

            string strMsg = string.Empty;
            if (Model != null)
            {
                strMsg = "此栏目已经存在！";
            }
            return strMsg;
        }

        /// <summary>
        /// 重写父类的保存数据方法
        /// </summary>
        /// <param name="intFormID">数据ID</param>
        /// <param name="strActionType">操作类型("ADD":"添加","UPDATE":"修改")</param>
        /// <returns></returns>
        public override bool SaveForm(int intFormID, string strActionType,int pid)
        {
            //执行 父类的方法
            base.SaveForm(intFormID, strActionType);

            //保存数据
            JH_MH_LMGL Model = new JH_MH_LMGLB().GetEntity(d => d.ID == intFormID);
            Model.Name = txtName.Text;
            Model.Number = txtNum.Text;
            Model.Link = txtLink.Text;
            Model.Remark = txtDetails.Text;
            Model.AuthUser = txtAuthUser.Text;
            Model.Type = Convert.ToInt32(ddlType.SelectedValue);
            Model.TopID = Convert.ToInt32(ddlTopID.SelectedValue);
            if (strActionType == "ADD")
            {
                Model.IsDel = 0;
            }
            return new JH_MH_LMGLB().Update(Model);
        }

        public override void initALLForm(string strFormCode)
        {
            new CommonHelp.BindData().BindLM(ddlTopID);
            ddlTopID.Items.Insert(0, new ListItem("无", "0"));
        }


        public override void initMangerForm(int intFormID, string strActionType)
        {
            base.initMangerForm(intFormID, strActionType);
            JH_MH_LMGL Model = new JH_MH_LMGLB().GetEntity(d => d.ID == intFormID);
            txtName.Text = Model.Name;
            txtNum.Text = Model.Number;
            txtLink.Text = Model.Link;
            txtAuthUser.Text = Model.AuthUser;
            txtDetails.Text = Model.Remark;
            ddlType.SelectedValue = Model.Type.ToString();
            ddlTopID.SelectedValue = Model.TopID.ToString();
        }

    }
}